#ifndef __ming_fyp_render_ResourceFactory_h__
#define __ming_fyp_render_ResourceFactory_h__

//------------------------------------------------------------------------------
// header includes
#include "fyp/render/ResCache.h"
#include "fyp/render/LoadingPolicy.h"

struct IDirect3DDevice9;
struct IDirect3DTexture9;
struct IDirect3DSurface9;
struct ID3DXEffect;
struct ID3DXMesh;

//------------------------------------------------------------------------------
namespace ming
{
namespace fyp
{
namespace render
{
	//--------------------------------------------------------------------------
	class TResourceFactory
	{
	public:
		//------------------------------
		// #cstor & #dstor
		TResourceFactory(IDirect3DDevice9 *device);
		~TResourceFactory();
		
		//------------------------------
		// external operations
		virtual IDirect3DTexture9* LoadTexture(const char* filename);
		virtual IDirect3DTexture9* LoadRenderedTexture(size_t format, size_t w, size_t h);
		virtual IDirect3DSurface9* LoadDepthBuffer(size_t w, size_t h);
		virtual ID3DXEffect* LoadEffect(const char* filename);
		virtual ID3DXMesh* LoadXMesh(const char* filename);

		virtual void UnloadTexture(IDirect3DTexture9* tex);
		virtual void UnloadRenderedTexture(IDirect3DTexture9* tex);
		virtual void UnloadDepthBuffer(IDirect3DSurface9* buf);
		virtual void UnloadEffect(ID3DXEffect* effect);
		virtual void UnloadXMesh(ID3DXMesh* xmesh);

	private:
		//------------------------------
		// internal attributes
		TResCache<IDirect3DTexture9, TD3DTextureLoadingPolicy> mTexCache;
		TResCache<IDirect3DTexture9, TD3DRenderedTextureLoadingPolicy> mRttCache;
		TResCache<IDirect3DSurface9, TD3DDepthBufferLoadingPolicy> mZBufCache;
		TResCache<ID3DXMesh, TD3DXMeshLoadingPolicy> mXMeshCache;
		TResCache<ID3DXEffect, TD3DXEffectLoadingPolicy> mEffectCache;
		
		//------------------------------
		// internal operations
	};
	
	//--------------------------------------------------------------------------
}
}
}


#endif	//__ming_fyp_render_ResourceFactory_h__